PROJECT = ~/text-categorization-som/text
ENCODE = ./tfidf.py
PRECLASS = ./preclass.sh

FILES_DIR = $(PROJECT)/data/document_encoding/documents

TRAIN_DIR = $(PROJECT)/data/sources/20news-bydate-train
TRAIN_OUT_DIR = $(PROJECT)/data/document_encoding/train_data
TRAIN_DOCUMENTS = $(TRAIN_DIR)/*/*
TRAIN_VECTOR = training_vectors.txt
TRAIN_DIRECTORIES = $(TRAIN_DIR)/alt.atheism $(TRAIN_DIR)/comp.graphics $(TRAIN_DIR)/comp.os.ms-windows.misc $(TRAIN_DIR)/comp.sys.ibm.pc.hardware $(TRAIN_DIR)/comp.sys.mac.hardware $(TRAIN_DIR)/comp.windows.x $(TRAIN_DIR)/misc.forsale $(TRAIN_DIR)/rec.autos $(TRAIN_DIR)/rec.motorcycles $(TRAIN_DIR)/rec.sport.baseball $(TRAIN_DIR)/rec.sport.hockey $(TRAIN_DIR)/sci.crypt $(TRAIN_DIR)/sci.electronics $(TRAIN_DIR)/sci.med $(TRAIN_DIR)/sci.space $(TRAIN_DIR)/soc.religion.christian $(TRAIN_DIR)/talk.politics.guns $(TRAIN_DIR)/talk.politics.mideast $(TRAIN_DIR)/talk.politics.misc $(TRAIN_DIR)/talk.religion.misc
TRAIN_PRECLASS_FILE = train_preclass.txt

TEST_DIR = $(PROJECT)/data/sources/20news-bydate-test
TEST_OUT_DIR = $(PROJECT)/data/document_encoding/test_data
TEST_DOCUMENTS = $(TEST_DIR)/*/*
TEST_VECTOR = test_vectors.txt
TEST_DIRECTORIES = $(TEST_DIR)/alt.atheism $(TEST_DIR)/comp.graphics $(TEST_DIR)/comp.os.ms-windows.misc $(TEST_DIR)/comp.sys.ibm.pc.hardware $(TEST_DIR)/comp.sys.mac.hardware $(TEST_DIR)/comp.windows.x $(TEST_DIR)/misc.forsale $(TEST_DIR)/rec.autos $(TEST_DIR)/rec.motorcycles $(TEST_DIR)/rec.sport.baseball $(TEST_DIR)/rec.sport.hockey $(TEST_DIR)/sci.crypt $(TEST_DIR)/sci.electronics $(TEST_DIR)/sci.med $(TEST_DIR)/sci.space $(TEST_DIR)/soc.religion.christian $(TEST_DIR)/talk.politics.guns $(TEST_DIR)/talk.politics.mideast $(TEST_DIR)/talk.politics.misc $(TEST_DIR)/talk.religion.misc
TEST_PRECLASS_FILE = test_preclass.txt

DIMENSION = 100
OUTFILE = encoding.out

all: preclass_train encode_train preclass_classify encode_classify

########################
# RULE: preclass_train
# DESCRIPTION: 
#      Get a preclassification of the documents
#      based on the directory they are in.
# INPUT: 
#     DIRECTORIES   -  A List of directory where the files are
# OUTPUT: 
#     TRAIN_PRECLASS_FILE - A preclassification file
########################
preclass_train: $(PRECLASS)
	mkdir $(TRAIN_OUT_DIR)
	$(PRECLASS) $(TRAIN_DIRECTORIES) > $(TRAIN_OUT_DIR)/$(TRAIN_PRECLASS_FILE)


########################
# RULE: preclass_classify
# DESCRIPTION: 
#      Get a preclassification of the documents
#      based on the directory they are in.
# INPUT: 
#     DIRECTORIES   -  A List of directory where the files are
# OUTPUT: 
#     TEST_PRECLASS_FILE - A preclassification file
########################
preclass_classify: $(PRECLASS)
	mkdir $(TEST_OUT_DIR)
	$(PRECLASS) $(TEST_DIRECTORIES) > $(TEST_OUT_DIR)/$(TEST_PRECLASS_FILE)

########################
# RULE: encode_train
# DESCRIPTION: 
#        Get the documents encoded into vectors
#        using TF-IDF
# INPUT: 
#    FILES_DIR  - Directory where the files are
#    DIMENSION  - Dimension of the generated vectors
#    TRAIN_VECTOR - Output file. Contains the encoded documents
# OUTPUT: 
#     OUTFILE   - Console output
########################
encode_train: $(ENCODE)
	rm -rf $(FILES_DIR)
	mkdir $(FILES_DIR)
	cp $(TRAIN_DOCUMENTS) $(FILES_DIR)
	$(ENCODE) $(FILES_DIR) $(DIMENSION) $(TRAIN_OUT_DIR)/$(TRAIN_VECTOR) >> $(TRAIN_OUT_DIR)/$(OUTFILE) 2>&1

########################
# RULE: encode_classify
# DESCRIPTION: 
#        Get the documents encoded into vectors
#        using TF-IDF
# INPUT: 
#    FILES_DIR  - Directory where the files are
#    DIMENSION  - Dimension of the generated vectors
#    TRAINING_VECTOR - Output file. Contains the encoded documents
# OUTPUT: 
#     OUTFILE   - Console output
########################
encode_classify: $(ENCODE)
	rm -rf $(FILES_DIR)
	mkdir $(FILES_DIR)
	cp $(TEST_DOCUMENTS) $(FILES_DIR)
	$(ENCODE) $(FILES_DIR) $(DIMENSION) $(TEST_OUT_DIR)/$(TEST_VECTOR) >> $(TEST_OUT_DIR)/$(OUTFILE) 2>&1

clean:
	rm -fr $(FILES_DIR) $(TEST_OUT_DIR) $(TRAIN_OUT_DIR) $(OUTFILE)
